package cst.a132wrx.recyclerviewtest132wrx.activity;


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.List;

import cst.a132wrx.recyclerviewtest132wrx.R;
import cst.a132wrx.recyclerviewtest132wrx.adapter.MyAdapter;
import cst.a132wrx.recyclerviewtest132wrx.bean.ArticleBean;
import cst.a132wrx.recyclerviewtest132wrx.iface.ArticleListener;
import cst.a132wrx.recyclerviewtest132wrx.model.ArticleModel;

public class MainActivity extends AppCompatActivity implements ArticleListener{
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter mAdapter;
    List<ArticleBean> list;
    private void initRecyclerView(){
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);//找到
        //创建默认的线性LayoutManager
        layoutManager = new LinearLayoutManager(this);
        //设置布局管理器
        recyclerView.setLayoutManager(layoutManager);
        //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        recyclerView.setHasFixedSize(true);
        //创建并设置Adapter
        //list = getData();
        mAdapter = new MyAdapter(this);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
        ArticleModel articlemodel=new ArticleModel();
        articlemodel.getResultList("article ",2,"2ts2j910hv4m270hipde4a67d7",this);
    }

    @Override
    public void onResponse(List<ArticleBean> list) {
        this.list=list;
        mAdapter.setList(list);


    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(this, "fail:"+msg, Toast.LENGTH_SHORT).show();

    }
}